home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Almathera Ten Pack 3: CDPD 3
/
Almathera Ten on Ten - Disc 3: CDPD3.iso
/
ab20
/
ab20_archive
/
utilities
/
emulators
/
unixlib.lzh
/
mktemp.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-10-19
|
1KB
|
32 lines
/* This function should return an unique string, I don't know how I can
* do that. The last try was wrong, it caused the parser to hang when
* starting telnet. With an 68000 it happened not often, but with a faster
* processor it happeded very often :+(
* But now I think it will work, this function is called by telnet and the
* parser, so let them both provide a template to which we shall append
* some string. The template must be large enough !!! The only problem left
* is what to do with 2 (or more) clients looking for a free name at the same
* time. Is Forbid()/Enable() enough or should I use semaphores ? The entire
* code until the port is in the list should be in the Forbid/Enable !!
*/
#include <stdio.h>
char *mktemp(char *template) {
static int count = 0;
char *tmp;
if(strlen(template) < 10 ) /* Too short !! */
return NULL;
tmp = template + strlen(template) - 8;
sprintf(tmp, "%08x", count);
Forbid(); /* Let no-one change the list while we are scanning it ! */
while(FindPort(template)) {
count++;
sprintf(tmp, "%08x", count);
}
Permit();
return template;
}